c++回文数````我很菜

来源:百度知道 编辑:UC知道 时间:2024/05/05 12:46:54
#include<iostream.h>
Int palindrome(int x)
{int y,s;s=0;y=x;
While(y>0)
{s=s*10+y%10;
Y=y/10;}
If(s==x)return 1;
Else return 0;}
Int main()
{int x;int temp;
Cout<<”Enter x”;
Cin>>x;
Temp=palindrome(x);
If(temp==1){cout<<”yes”<<endl;}
Else {cout<<”no”<<endl;}
Return 0;}
这个程序只能在5位数以内正确输出```怎么办````
还有 return 0和return 1是什么意思````
谢谢`````
我换了long int还是不行啊~~~~~

错误有几个:
1. C++是大小写敏感的语言,If和if是完全不一样的。C++里面的if、else、while、return所有字母都应该用小写。
2. C++代码里面只能识别ascii码,你代码中的引号是不能被识别的。
3. 这个也不能算错误,把其中的几个int换成long int之后应该可以长一些(这个看一下我的代码)。比如你输入333333333试试看。long int是64位的,应该能满足你的需求。
你是在word里面写的上面这段代码??我觉得就写代码而言,记事本比word都要好用很多。

return是返回值。在主程序里面的语句
temp=palindrome(x);
调用了palindrome函数,temp接受这个函数处理返回的结果,即palindrome中的两句return后面的值(即0或者1)。

这个是改以后的代码,你看看。
#include<iostream.h>

int palindrome(long int x)
{
long int y;
long int s=0;
y=x;
while(y>0)
{
s=s*10+y%10;
y=y/10;
}
if(s==x)
return 1;
else
return 0;
}

int main()
{
long int x;
int temp;
cout<<"Enter x";
cin>>x;

temp = palindrome(x);

if(temp==1)
{
cout<<"yes"<<endl;
}
else {
cout<<"no"